package com.push.notifications;

import com.push.cache.ImageLoader;
import com.push.notifications.R;
import java.util.List;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import android.widget.ToggleButton;

 public class UI_ListHistory extends ArrayAdapter<categoryItem> {
    
    private  static List<categoryItem> list;
    private   Activity context;
    private View curCheckBoxView; 
    
    public ImageLoader imageLoader;
    
    public UI_ListHistory(Activity context, List<categoryItem> list) {
        super(context, R.layout.list_sevice, list);
        this.context = context;
        this.list = list;
        imageLoader=new ImageLoader(this.context.getApplicationContext());
    }
    
    static class ViewHolderHistory {
        protected TextView text;
        protected TextView textDesc;
        protected ToggleButton checkbox;
        protected ImageView image;
        protected Button image_play;
        protected int post;
    }
    
    public Activity getParrentContext()
    {
    	return context;
    }
    public void updateStatus(categoryItem model)
    {
    	ViewHolderHistory viewHolder = null;
    	viewHolder = new ViewHolderHistory();
    	viewHolder.checkbox = (ToggleButton) curCheckBoxView.findViewById(R.id.checkBox1);    
        viewHolder.checkbox.setChecked(model.isSelected());
        list.set(model.getPos(), model);
    }
    @Override
    public View getView( int position, View convertView, ViewGroup parent) {
        
    	ViewHolderHistory viewHolder = null;
        
        if (convertView == null && list != null) {
            LayoutInflater inflator = context.getLayoutInflater();
            Log.e("View", "convertView == null:-------------------------");
            convertView = inflator.inflate(R.layout.sub_list_sevice, null);
            convertView.setClickable(true);
           // convertView.setOnClickListener( ( (HistoryListActivity) context).myClickListener);
            //convertView.setOnClickListener( ( (newsTabManager) context).myClickListener);
            viewHolder = new ViewHolderHistory();
            categoryItem model1 =list.get(position);
            if(model1 != null)
            {           
                viewHolder.text = (TextView) convertView.findViewById(R.id.slable);
                viewHolder.text.setText(model1.name) ;                                         
                viewHolder.textDesc = (TextView) convertView.findViewById(R.id.text55);                             
                viewHolder.image = (ImageView) convertView.findViewById(R.id.logo10);
                imageLoader.DisplayImage(model1.s_image, viewHolder.image);
             } 
            convertView.setTag(viewHolder);
            convertView.setTag(R.id.slable, viewHolder.text);
            convertView.setTag(R.id.logo10, viewHolder.image);
            convertView.setTag(R.id.text55, viewHolder.textDesc);
            
        }
        else {
            Log.e("View", "convertView !!!= null:-------------------------");
            viewHolder = (ViewHolderHistory) convertView.getTag();
        }
        

        //
        categoryItem model2 =list.get(position);
        viewHolder.text.setTag(position); // This line is important.
        viewHolder.image.setTag(position); // This line is important.
        viewHolder.textDesc.setTag(position); // This line is important.
        viewHolder.post=position;
        imageLoader.DisplayImage(model2.s_image, viewHolder.image);
        viewHolder.text.setText(model2.name);

        //viewHolder.image.setImageURI(url);
        return convertView;
    }
    	
} 
